using System;
using UnityEngine;

public class CamRotate : MonoBehaviour
{
	private bool isDrag;

	private Vector2 dragDeta;

	public UIEventListener rotateAreaBtn;

	public Transform tempTarget;

	private void Start()
	{
		UIEventListener uIEventListener = rotateAreaBtn;
		uIEventListener.onPress = (UIEventListener.BoolDelegate)Delegate.Combine(uIEventListener.onPress, new UIEventListener.BoolDelegate(OnPressArea));
		UIEventListener uIEventListener2 = rotateAreaBtn;
		uIEventListener2.onDrag = (UIEventListener.VectorDelegate)Delegate.Combine(uIEventListener2.onDrag, new UIEventListener.VectorDelegate(OnDragCam));
		tempTarget = base.transform;
	}

	private void LateUpdate()
	{
		rotateFun();
		isDrag = false;
	}

	public void rotateFun()
	{
		if (isDrag)
		{
			Transform transform = tempTarget;
			Vector3 localEulerAngles = tempTarget.localEulerAngles;
			float x = localEulerAngles.x;
			Vector3 localEulerAngles2 = tempTarget.localEulerAngles;
			float y = localEulerAngles2.y;
			Vector3 localEulerAngles3 = tempTarget.localEulerAngles;
			float y2 = Mathf.Lerp(y, localEulerAngles3.y + dragDeta.x * 3f, Time.deltaTime * 8f);
			Vector3 localEulerAngles4 = tempTarget.localEulerAngles;
			transform.localRotation = Quaternion.Euler(x, y2, localEulerAngles4.z);
		}
	}

	public void OnDragCam(GameObject obj, Vector2 deta)
	{
		dragDeta = deta;
		isDrag = true;
	}

	public void OnPressArea(GameObject obj, bool press)
	{
		if (!press)
		{
			dragDeta = Vector2.zero;
		}
	}
}
